package com.xuantu.learn.core.string;

/**
 * java String基础
 * @author fengzp
 *
 */
public class StringDemo {
	
	public static void main(String[] args) {
		String a = "123";
		String b = new String("123");
		String c = "123";
		System.out.printf("a:%s,b:%s,a=b:%b\n", a, b, a==b);
//		System.out.printf("a.hashCode=%d\n", a.hashCode());
//		System.out.printf("b.hashCode=%d\n", b.hashCode());
//		System.out.printf("c.hashCode=%d\n", c.hashCode());
		System.out.printf("a:%s\n", Integer.toHexString(System.identityHashCode(a)));
		System.out.printf("b:%s\n", Integer.toHexString(System.identityHashCode(b)));
		System.out.printf("c:%s\n", Integer.toHexString(System.identityHashCode(c)));
		b = new String("123");
		System.out.printf("d:%s\n", Integer.toHexString(System.identityHashCode(b)));
//		a:123,b:123,a=b:false
//		a:4aa298b7
//		b:7d4991ad
//		c:4aa298b7
//		d:28d93b30
		
		
		short s1 = 1;
		s1 += 1;
		System.out.println(s1);
		short s2 = 1;
//		s2 = s2 + 1;    //报错cannot convert from int to short
//		System.out.println(s2);
		
		System.out.println(1 << 8);  //左移 低位补0   1-> 100000000  = 2 << 7
		System.out.println(2 * 2 * 2 * 2 * 2 * 2 * 2 * 2);  //等于2的8次方
		System.out.printf("%s\n", Integer.toBinaryString(256));
		
		System.out.printf("3<<3 = %d\n", 3 << 3);  //    11->11000  3乘以2的3次方
		System.out.printf("-3<<3 = %d\n", -3 << 3);  //    11->11000  丢弃左边符号位
		System.out.printf("%s\n", Integer.toBinaryString(24));
		System.out.println(Integer.toBinaryString(-3));
		System.out.println(Integer.toBinaryString(3));
		
		int i8 = 010;  //8进制
		System.out.println("i8=" + i8);
		int i16 = 0xE; //16进制
		System.out.println("i16=" + i16);
		int i2 = 0b10; //2进制
		System.out.println("i2=" + i2);
		System.out.printf("%o\n", 10); ////8进制
		System.out.printf("%x\n", 10); ////16进制
		System.out.printf("%d\n", 10); ////10进制
		
		
		
		
		//System.out.println(-2 >>> 1); //0填高位  0010
		//System.out.println(-2 >> 1);  //符号位填高位 010
		//System.out.printf("%o", -2);
		
		
	}
}
